package com.mikalai.dao.jdbc.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;

import javax.sql.DataSource;

import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.object.MappingSqlQuery;

import com.mikalai.dao.jdbc.bean.Contact;

public class SelectContactByFirstName extends MappingSqlQuery<Contact> {
   private static final String SQl = "select id, first_name, last_name, birth_date from contact where first_name = :first_name";
    
    public SelectContactByFirstName(DataSource ds){
        super(ds, SQl);
        super.declareParameter(new SqlParameter("first_name", Types.VARCHAR));
    }
    
    @Override
    protected Contact mapRow(ResultSet rs, int i) throws SQLException {
        Contact contact = new Contact();
        contact.setId(rs.getLong("id"));
        contact.setFirstName(rs.getString("first_name"));
        contact.setLastName(rs.getString("last_name"));
        contact.setBirthDate(rs.getDate("birth_date"));
        return contact;
    }
}
